/**
 * Created by zhubuqing on 2018/4/18.
 */
var getNewsUrl = baseUrl + "/common/resource/getNews";
var searchCommonResourceUrl = baseUrl + "/common/resource/searchCommonResource";

$(function () {
    // 获取实践案例
    $("#toXqListSjal").html('<a href="xq_list.html?type=zjjs_shiJianAnLi">更多</a>');
    getNewsShiJianAnLi();

    // 获取红船精神
    $("#toXqListHcjs").html('<a href="xq_list.html?type=zjjs_hongChuanJingShen">更多</a>');
    getNewsHongChuanJingShen();

    // 获取浙江新闻
    $("#toXqListZjxw").html('<a href="xq_list.html?type=zjjs_zheJiangXinWen">更多</a>');
    getNewsZheJiangXinWen();

    // 理论研究
    $("#toXqListLlyj").html('<a href="xq_list.html?type=zjjs_liLunYanJiu">更多</a>');
    getNewsLiLunYanJiu();

    // 浙江视频
    $("#toXqListZjsp").html('<a href="xq_list.html?type=zjjs_zheJiangShiPin">更多</a>');
    searchCommonResourceZheJiangShiPin();
})
// 获取实践案例
function getNewsShiJianAnLi() {
    var data = {
        commonNewsTypeId: 3,
        bookId: 6,
        status: "UP",
        page: 0,
        size: 10
    };

    commonAjax(getNewsUrl, data, "getNewsShiJianAnLiRes", "GET");
}
function getNewsShiJianAnLiRes(res) {
    var resultData = res.obj.content;

    var newsShiJianAnLiFirstHtml = "";
    var newsShiJianAnLiHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        if (i == 0) {
            newsShiJianAnLiFirstHtml += '<a onclick=toXqNormal("' + resultData[i].id + '","zjjs_shiJianAnLi")><img src="' + resultData[i].pic + '" alt="" width="100%;height:150px;">';
            newsShiJianAnLiFirstHtml += '<div class="bigNew clearfix">';
            newsShiJianAnLiFirstHtml += '<p class="bigNewFont" style="width:365px;">' + resultData[i].title + '</p>';
            newsShiJianAnLiFirstHtml += '<p class="smallNewFont">' + resultData[i].abstructContent + '</p>';
            newsShiJianAnLiFirstHtml += '<div class="time pull-right">' + changeTime(resultData[i].creatTime) + '</div>';
            newsShiJianAnLiFirstHtml += '</div></a>';
        } else {
            newsShiJianAnLiHtml += '<a onclick=toXqNormal("' + resultData[i].id + '","zjjs_shiJianAnLi")><li class="clearfix">';
            newsShiJianAnLiHtml += '<p class="bigTitle">' + resultData[i].title + '</p>';
            newsShiJianAnLiHtml += '<div class="time pull-right">' + changeTime(resultData[i].creatTime) + '</div>';
            newsShiJianAnLiHtml += '</li></a>';
        }
    }

    $("#newsShiJianAnLiFirst").html(newsShiJianAnLiFirstHtml);
    $("#newsShiJianAnLi").html(newsShiJianAnLiHtml);
}

// 获取红船精神
function getNewsHongChuanJingShen() {
    var data = {
        commonNewsTypeId: 4,
        bookId: 6,
        page: 0,
        size: 10
    };

    commonAjax(getNewsUrl, data, "getNewsHongChuanJingShenRes", "GET");
}
function getNewsHongChuanJingShenRes(res) {
    var resultData = res.obj.content;

    var newsHongChuanJingShenHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        newsHongChuanJingShenHtml += '<a onclick=toXqNormal("' + resultData[i].id + '","zjjs_hongChuanJingShen")><li>' + resultData[i].title + '</li></a>';
    }

    $("#newsHongChuanJingShen").html(newsHongChuanJingShenHtml);
}

// 获取浙江新闻
function getNewsZheJiangXinWen() {
    var data = {
        newsTypeId: 2,
        status: "UP",
        page: 0,
        size: 10
    };

    commonAjax(baseUrl + "/common/firstPage/searchCommonNews", data, "getNewsZheJiangXinWenRes", "GET");
}
function getNewsZheJiangXinWenRes(res) {
    var resultData = res.obj.content;

    var newsZheJiangXinWenHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        newsZheJiangXinWenHtml += '<a onclick=toXqNormal("' + resultData[i].id + '","zjjs_zheJiangXinWen")><li class="clearfix">';
        newsZheJiangXinWenHtml += '<div class="pull-left News">' + resultData[i].title + '</div>';
        newsZheJiangXinWenHtml += '<div class="pull-right time">' + changeTime(resultData[i].creatTime) + '</div>';
        newsZheJiangXinWenHtml += '</li></a>';
    }

    $("#newsZheJiangXinWen").html(newsZheJiangXinWenHtml);
}

// 获取理论研究
function getNewsLiLunYanJiu() {
    var data = {
        commonNewsTypeId: 2,
        bookId: 6,
        status: "UP",
        page: 0,
        size: 10
    };

    commonAjax(getNewsUrl, data, "getNewsLiLunYanJiuRes", "GET");
}
function getNewsLiLunYanJiuRes(res) {
    var resultData = res.obj.content;

    var newsLiLunYanJiuHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        newsLiLunYanJiuHtml += '<a onclick=toXqNormal("' + resultData[i].id + '","zjjs_liLunYanJiu")><li class="clearfix">';
        newsLiLunYanJiuHtml += '<div class="pull-left News">' + resultData[i].title + '</div>';
        newsLiLunYanJiuHtml += '<div class="pull-right time">' + changeTime(resultData[i].creatTime) + '</div>';
        newsLiLunYanJiuHtml += '</li></a>';
    }

    $("#newsLiLunYanJiu").html(newsLiLunYanJiuHtml);
}

// 获取浙江视频
function searchCommonResourceZheJiangShiPin() {
    var data = {
        type: "ZHE_JIANG_VIDEO",
        bookId: 6,
        status: "UP",
        page: 0,
        size: 10
    };

    commonAjax(searchCommonResourceUrl, data, "searchCommonResourceZheJiangShiPinRes", "GET");
}
function searchCommonResourceZheJiangShiPinRes(res) {
    var resultData = res.obj.content;

    var commonResourceZheJiangShiPinHtml = "";

    for (var i = 0; i < resultData.length; i++) {
        if (resultData[i].field4 == "1") {
            commonResourceZheJiangShiPinHtml += '<a href="' + resultData[i].fileUrl + '"><div class="imgBoxList">';
        } else {
            commonResourceZheJiangShiPinHtml += '<a onclick=toXqVideo("' + resultData[i].id + '","zjjs_zheJiangShiPin")><div class="imgBoxList">';
        }
        commonResourceZheJiangShiPinHtml += '<img src="' + resultData[i].pic + '" alt="">';
        commonResourceZheJiangShiPinHtml += '<p>' + resultData[i].title + '</p>';
        commonResourceZheJiangShiPinHtml += '<p class="time">' + resultData[i].schoolName + '</p>'
        commonResourceZheJiangShiPinHtml += '</div></a>';
    }

    $("#commonResourceZheJiangShiPin").html(commonResourceZheJiangShiPinHtml);
}

// 跳转至详情
function toXqNormal(followId, type) {
    var followId = followId;
    var theType = type;
    sessionStorage.setItem("followId", JSON.stringify(followId));
    sessionStorage.setItem("type", JSON.stringify(theType));
    self.location.href = "xq.html";
}

// 跳转至视频
function toXqVideo(followId, type) {
    var followId = followId;
    var theType = type;
    sessionStorage.setItem("followId", JSON.stringify(followId));
    sessionStorage.setItem("type", JSON.stringify(theType));
    window.open("video.html");
}